package com.tengfei.blogsystem.controller.admin;

/**
 * @version v1.0
 * @author} feige
 * @date 2021-10-15-16:22
 * @description
 */

import com.tengfei.blogsystem.response.ResponseResult;
import com.tengfei.blogsystem.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户管理api
 */
@RestController
@RequestMapping("/admin/user")
public class UserAdminApi {

    @Autowired
    IUserService userService;


    /**
     * 获取用户列表
     *
     * @param page
     * @param size
     * @return
     */
    @PreAuthorize("@permission.admin()")
    @GetMapping("/list/{page}/{size}")
    public ResponseResult listUser(@PathVariable("page") int page, @PathVariable("size") int size,
                                   HttpServletRequest request,
                                   HttpServletResponse response) {
        return userService.listUser(page, size, request, response);
    }

    /**
     * 删除用户
     *
     * @param userId
     * @return
     */
    @PreAuthorize("@permission.admin()")
    @DeleteMapping("/{userId}")
    public ResponseResult deleteUserById(HttpServletRequest request, HttpServletResponse response, @PathVariable("userId") String userId) {
        return userService.deleteUserById(request, response, userId);
    }

    /**
     * 重置用户密码
     *
     * @param userId
     * @return
     */
    @PutMapping("/{userId}")
    public ResponseResult resetUserPassWord(@PathVariable("userId") String userId) {

        return null;
    }

}
